package com.niiwoo.civet.trade.configuration;

import com.niiwoo.civet.trade.constant.RabbitConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by zhangwanli on 2017/11/17.
 */
@Configuration
public class InvestmentMqConfiguration {

    //**********************
    //自动投资配置,标的上标时入MQ队列
    //**********************
    @Bean
    public Exchange autoInvestProjectExchange() {
        return new DirectExchange(RabbitConstant.Exchange.AUTO_INVEST_PROJECT, true, true);
    }

    @Bean
    public Queue autoInvestProjectQueue() {
        return new Queue(RabbitConstant.Queue.AUTO_INVEST_PROJECT, true);
    }

    @Bean
    public Binding autoInvestProjectBinding() {
        return BindingBuilder.bind(autoInvestProjectQueue()).to(autoInvestProjectExchange()).with(RabbitConstant.RoutingKey.AUTO_INVEST_PROJECT).noargs();
    }

    //**********************
    //批量投资配置,投资人确认批量投资后入MQ队列异步处理
    //**********************
    @Bean
    public Exchange batchInvestorExchange() {
        return new DirectExchange(RabbitConstant.Exchange.BATCH_INVESTOR, true, true);
    }

    @Bean
    public Queue batchInvestorQueue() {
        return new Queue(RabbitConstant.Queue.BATCH_INVESTOR, true);
    }

    @Bean
    public Binding batchInvestorBinding() {
        return BindingBuilder.bind(batchInvestorQueue()).to(batchInvestorExchange()).with(RabbitConstant.RoutingKey.BATCH_INVESTOR).noargs();
    }

    //**********************
    //批量投资成功配置,入MQ队列异步处理发送通知等
    //**********************
    @Bean
    public Exchange batchInvestSucceedExchange() {
        return new DirectExchange(RabbitConstant.Exchange.BATCH_INVEST_FINISHED, true, true);
    }

    @Bean
    public Queue batchInvestSucceedQueue() {
        return new Queue(RabbitConstant.Queue.BATCH_INVEST_FINISHED, true);
    }

    @Bean
    public Binding batchInvestSucceedBinding() {
        return BindingBuilder.bind(batchInvestSucceedQueue()).to(batchInvestSucceedExchange()).with(RabbitConstant.RoutingKey.BATCH_INVEST_FINISHED).noargs();
    }

    //**********************
    //批量、自动投资签署委托授权协议合同,确认设置后入MQ队列异步签合同
    //**********************
    @Bean
    public Exchange signCommissionAuthAgreementExchange() {
        return new DirectExchange(RabbitConstant.Exchange.SIGN_COMMISSION_AUTH_AGREEMENT, true, true);
    }

    @Bean
    public Queue signCommissionAuthAgreementQueue() {
        return new Queue(RabbitConstant.Queue.SIGN_COMMISSION_AUTH_AGREEMENT, true);
    }

    @Bean
    public Binding signCommissionAuthAgreementBinding() {
        return BindingBuilder.bind(signCommissionAuthAgreementQueue())
                .to(signCommissionAuthAgreementExchange())
                .with(RabbitConstant.RoutingKey.SIGN_COMMISSION_AUTH_AGREEMENT).noargs();
    }

    //**********************
    //签署风险提示书合同，生成投资订单后入MQ队列异步处理签署法大大合同
    //**********************
    @Bean
    public Exchange signRiskTipsAgreementExchange() {
        return new DirectExchange(RabbitConstant.Exchange.SIGN_RISK_TIPS_AGREEMENT, true, true);
    }

    @Bean
    public Queue signRiskTipsAgreementQueue() {
        return new Queue(RabbitConstant.Queue.SIGN_RISK_TIPS_AGREEMENT, true);
    }

    @Bean
    public Binding signRiskTipsAgreementBinding() {
        return BindingBuilder.bind(signRiskTipsAgreementQueue())
                .to(signRiskTipsAgreementExchange())
                .with(RabbitConstant.RoutingKey.SIGN_RISK_TIPS_AGREEMENT).noargs();
    }

    //**********************
    //系统投资配置变更
    //**********************
    @Bean
    public Exchange sysInvestConfigChangedExchange() {
        return new DirectExchange(RabbitConstant.Exchange.SYS_INVEST_CONFIG_CHANGE, true, true);
    }

    @Bean
    public Queue sysInvestConfigChangedQueue() {
        return new Queue(RabbitConstant.Queue.SYS_INVEST_CONFIG_CHANGE, true);
    }

    @Bean
    public Binding sysInvestConfigChangedBinding() {
        return BindingBuilder.bind(sysInvestConfigChangedQueue())
                .to(sysInvestConfigChangedExchange())
                .with(RabbitConstant.RoutingKey.SYS_INVEST_CONFIG_CHANGE).noargs();
    }

}
